from flask import Flask, render_template, url_for

app = Flask(__name__)

@app.route('/')
def home():
    return render_template('index.html')

@app.route('/resources')
def resource_list():
    # 在视图函数中生成 URL
    resources = [
        {"id": 1, "title": "搜索引擎", "type": "text", "content": "", "thumbnail": None},
        {"id": 2, "title": "交通出行", "type": "text", "content": "", "thumbnail": None},
        {"id": 3, "title": "在线购物", "type": "text", "content": "", "thumbnail": None},
        {"id": 4, "title": "图像识别", "type": "text", "content": "", "thumbnail": None},
        {"id": 5, "title": "医疗诊断", "type": "text", "content": "", "thumbnail": None},
        {"id": 6, "title": "艺术创作", "type": "text", "content": "", "thumbnail": None},
        {"id": 7, "title": "语言翻译", "type": "text", "content": "", "thumbnail": None},
        {"id": 8, "title": "体育运动", "type": "text", "content": "", "thumbnail": None}
    ]
    return render_template('resource_list.html', resources=resources)

@app.route('/resource/<int:resource_id>')
def resource_detail(resource_id):
    # 在这里获取资源数据
    with open("templates/search.html") as se:
        search = se.read()
    with open("templates/map.html") as ma:
        map = ma.read()
    with open("templates/buy.html") as bu:
        buy = bu.read()
    with open("templates/pic.html") as pi:
        pic = pi.read()
    with open("templates/med.html") as me:
        med = me.read()
    with open("templates/art.html") as ar:
        art = ar.read()
    with open("templates/translate.html") as tr:
        translate = tr.read()
    with open("templates/sport.html") as sp:
        sport = sp.read()
    resources = [
        {"id": 1, "title": "搜索引擎", "type": "text", "content": search},
        {"id": 2, "title": "交通出行", "type": "text", "content": map},
        {"id": 3, "title": "在线购物", "type": "text", "content": buy},
        {"id": 4, "title": "图像识别", "type": "text", "content": pic},
        {"id": 5, "title": "医疗诊断", "type": "text", "content": med},
        {"id": 6, "title": "艺术创作", "type": "text", "content": art},
        {"id": 7, "title": "语言翻译", "type": "text", "content": translate},
        {"id": 8, "title": "体育运动", "type": "text", "content": sport}
    ]
    resource = next((r for r in resources if r['id'] == resource_id), None)
    return render_template('resource_detail.html', resource=resource)

if __name__ == '__main__':
    app.run(debug=True, host="0.0.0.0", port=80)
